using System;
using System.Collections.Generic;
using System.Text;

using System.ComponentModel;
using System.Drawing.Design;
using System.Drawing;
 
namespace Adoor.VSDesigner.CollectionEditor
{
    public class LinkedDomainGroupEditor : BaseDataCollectionEditor
    {
        public LinkedDomainGroupEditor(Type type)
            : base(type)
        {
        }

        protected override bool CanRemoveInstance(object value)
        {
            Adoor.Object.Domain.ObjectDomain dom1 = (Adoor.Object.Domain.ObjectDomain)value;
            if (dom1.GetType().IsSubclassOf(typeof(Adoor.Object.Domain.ObjectDomain)))
            {
                return false;
            }
            return true;
            //return this.DomainCollection.CanRemove(table1);
        }

        protected override object CreateInstance(Type type)
        {
            object obj1 = base.CreateInstance(type);
            Adoor.Object.Domain.ObjectDomain dom1 = (Adoor.Object.Domain.ObjectDomain)obj1;
            //string text1 = DataDesignUtil.GetUniqueTableName(this.DomainCollection, "Table", 1);
            this.DomainGroup.Add(dom1);
            return obj1;
        }

        protected override void DestroyInstance(object value)
        {
            this.DomainGroup.Remove((Adoor.Object.Domain.ObjectDomain)value);
            base.DestroyInstance(value);
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            base.EditValueMask &= -33;
            object obj1 = context.Instance;
            if ((obj1 != null) && (obj1 is Adoor.Object.Domain.LinkedDomainGroup))
            {
                this.DomainGroup = (Adoor.Object.Domain.LinkedDomainGroup)obj1;
            }
            if (this.DomainGroup.GetType().IsSubclassOf(typeof(Adoor.Object.Domain.LinkedDomainGroup)))
            {
                base.EditValueMask &= -129;
            }
            this.ObjectDomain = (Adoor.Object.Domain.ObjectDomain)value;
            object obj2 = base.EditValue(context, provider, value);
            this.DomainGroup = null;
            this.ObjectDomain = null;
            return obj2;
        }

        protected override void OnFormCreated()
        {
            base.DisplayedPropertyName = "LinkedDomainGroup";
        }


        protected override string FormCaption
        {
            get
            {
                return "Edit LinkedDomainGroup";
            }
        }
        protected override string HelpTopic
        {
            get
            {
                return "vs.data.collectioneditor.table";
            }
        }

        private Adoor.Object.Domain.LinkedDomainGroup DomainGroup;
        private Adoor.Object.Domain.ObjectDomain ObjectDomain;
    }


}
